import axios from '@/utils/request';

/**
 * 根据条件查询订单列表
 */
export async function QueryOrderViewByParams(params) {
    const res = await axios.post('/Order/QueryOrderViewByOrderPageList',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 根据条件修改订单
 * @params 订单对像
 */
 export async function UpdateOrder(params) {
    const res = await axios.post('/Order/UpdateOrderView',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 确认收货
 * @params 订单对像
 */
export async function ConfirmReceipt(id) {
    const res = await axios.post('/Order/ConfirmReceipt?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 取消订单
 * @params 订单对像
 */
export async function CancelOrder(id) {
    const res = await axios.post('/Order/CancelOrder?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 根据条件删除订单
 * @id 订单id
 */
 export async function DeleteOrder(id) {
    const res = await axios.post('/Order/DeleteOrder?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 根据订单Id查询订单信息
 * @id 订单id
 */
 export async function QueryOrderViewById(id) {
    const res = await axios.get('/order/QueryOrderViewById?id='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 根据订单Id查询订单信息
 * @id 订单id
 */
 export async function QueryOrderOutStockViewById(id) {
    const res = await axios.get('/Order/QueryOrderOutStockViewById?id='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据条件修改订单
 * @params 订单对像
 */
 export async function Update(params) {
    const res = await axios.post('/Order/Update',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 根据订单Id查询订单信息
 * @id 订单id
 */
 export async function QueryOrderById(id) {
    const res = await axios.get('/order/GetModelById/'+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加订单配送信息
 * @params 订单对像
 */
 export async function AddDelivery(params) {
    const res = await axios.post('/Order/AddDelivery',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 打印
 */
export async function PrintSaleOrderById(id) {
    const res = await axios.post('/Order/DoPrintOrder?id='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}